<?php



namespace App\Services\Company\Models;

use App\Services\Member\Models\User;
use App\Services\Company\Models\CompanyOrder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class CompanyOrderPaidRecord extends Model
{
    use SoftDeletes,HasFactory;

    const PAID_TYPE_DEFAULT = 0;
    const PAID_TYPE_PROMO_CODE = 1;
    const PAID_TYPE_INVITE_BALANCE = 2;
    const PAID_TYPE_COUPON_CODE = 3;


    const PAID_TYPE_TEXT = [
        self::PAID_TYPE_DEFAULT => '直接支付',
        self::PAID_TYPE_INVITE_BALANCE => '邀请余额支付',
        self::PAID_TYPE_PROMO_CODE => '邀请码支付',
        self::PAID_TYPE_COUPON_CODE => '优惠券支付',
    ];

    protected $table = 'company_order_paid_records';

    protected $fillable = [
        'user_id', 'order_id', 'paid_total', 'paid_type', 'paid_type_id','company_id',
    ];

    protected $appends = [
        'paid_type_text',
    ];

    public function getPaidTypeTextAttribute()
    {
        return self::PAID_TYPE_TEXT[$this->paid_type] ?? '';
    }

    public function order()
    {
        return $this->belongsTo(CompanyOrder::class, 'order_id');
    }
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id');
    }
}
